﻿using PMS.Data.DbUtils;
using PMS.Data.Entities.Medias;
using PMS.Services.Caching.Extensions;
using System.Collections.Generic;
using System.Linq;

namespace PMS.Services.EntityServices.Medias
{
    /// <summary>
    /// Task service
    /// </summary>
    public partial class MimeTypesService : IMimeTypesService
    {
        #region Fields

        private readonly IRepository<MimeTypes> _mimetypesRepository;
        #endregion

        #region Ctor

        public MimeTypesService(IRepository<MimeTypes> mimetypesRepository)
        {
            _mimetypesRepository = mimetypesRepository;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Gets a mimetype
        /// </summary>
        /// <param name="mimeId">mimetypes identifier</param>
        /// <returns>Task</returns>
        public virtual MimeTypes GetMimeTypesById(int mimeId)
        {
            if (mimeId == 0)
                return null;

            return _mimetypesRepository.ToCachedGetById(mimeId);
        }

        /// <summary>
        /// Get All MimeTypes List
        /// </summary>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <returns>Tasks</returns>
        public virtual IList<MimeTypes> GetMimeTypesAll(bool showHidden = false)
        {
            var key = CacheKeyConfigs.MimeTypesAllCacheKey;
            var query = _mimetypesRepository.Table;
            if (!showHidden)
                query = query.Where(m => m.IsActive);
            return query.ToCachedList(key);
        }

        #endregion
    }
}
